package il.ac.mta.javaweb.ex1.logic;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

/**
 * This class represents a battle ship in the game
 * 
 * 
 */
public class BattleShip
{
	private Point topLeftPosition = new Point();
	private int length = 0;
	private ShipDirection direction = ShipDirection.HORIZONTAL;
	private List<ShipSqaure> shipSqaures = new ArrayList<ShipSqaure>();

	public BattleShip(int length, Point topLeftPosition, ShipDirection direction)
	{
		this.setLength(length);
		this.setTopLeftPosition(topLeftPosition);
		this.setDirection(direction);

		this.InitializeSquares();
	}

	public Point getTopLeftPosition()
	{
		return this.topLeftPosition;
	}

	public void setTopLeftPosition(Point topLeftPosition)
	{
		this.topLeftPosition = topLeftPosition;
	}

	public int getLength()
	{
		return this.length;
	}

	private void setLength(int length)
	{
		this.length = length;
	}

	public ShipDirection getDirection()
	{
		return this.direction;
	}

	private void setDirection(ShipDirection direction)
	{
		this.direction = direction;
	}

	public List<ShipSqaure> getShipSqaures()
	{
		return this.shipSqaures;
	}

	private void InitializeSquares()
	{
		for (int i = 0; i < length; ++i)
		{
			ShipSqaure square = new ShipSqaure();

			switch (direction)
			{
				case HORIZONTAL:
					square.setPosition(new Point(topLeftPosition.x + i,
							topLeftPosition.y));
					break;
				case VERTICAL:
					square.setPosition(new Point(topLeftPosition.x,
							topLeftPosition.y + i));
					break;
				default:
					break;
			}

			shipSqaures.add(square);
		}
	}
}
